using System;
using System.Collections.Generic;
using System.Text;

namespace IGlobalist.Cms.Model
{
    [Serializable]
    public class CmsObject : ICmsObject
    {
        #region IBaseCmsObject Members
        private long _ID = 0L;
        public long ID
        {
            get
            {
                return _ID;
            }
            set
            {
                _ID = value;
            }
        }

        private long _ParentID = 0;
        public long ParentID
        {
            get
            {
                return _ParentID;
            }
            set
            {
                _ParentID = value;
            }
        }
        private long _FirstVersionID = 0L;

        public long FirstVersionID
        {
            get { return _FirstVersionID; }
            set { _FirstVersionID = value; }
        }

        private string _Name = string.Empty;
        public string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                _Name = value;
            }
        }

        private string _Description = string.Empty;
        public string Description
        {
            get
            {
                return _Description;
            }
            set
            {
                _Description = value;
            }
        }

        private long _Author = 0L;
        public long Author
        {
            get
            {
                return _Author;
            }
            set
            {
                _Author = value;
            }
        }

        private short _Version = 0;
        public short Version
        {
            get
            {
                return _Version;
            }
            set
            {
                _Version = value;
            }
        }

        private DateTime _CreatedDate = DateTime.Now;
        public DateTime CreatedDate
        {
            get
            {
                return _CreatedDate;
            }
            set
            {
                _CreatedDate = value;
            }
        }

        private long _EditedBy = 0;
        public long EditedBy
        {
            get
            {
                return _EditedBy;
            }
            set
            {
                _EditedBy = value;
            }
        }

        private DateTime _EditedDate = DateTime.Now;
        public DateTime EditedDate
        {
            get
            {
                return _EditedDate;
            }
            set
            {
                _EditedDate = value;
            }
        }

        private string _Tags = string.Empty;
        public string Tags
        {
            get
            {
                return _Tags;
            }
            set
            {
                _Tags = value;
            }
        }

        private string _Lang = "en-US";
        public string Lang
        {
            get
            {
                return _Lang;
            }
            set
            {
                _Lang = value;
            }
        }

        private ContentStatus _Status = ContentStatus.Creating;
        public ContentStatus Status
        {
            get
            {
                return _Status;
            }
            set
            {
                _Status = value;
            }
        }

        private string[] _VisibleRoles = new string[] { "All" };
        public string[] VisibleRoles
        {
            get
            {
                return _VisibleRoles;
            }
            set
            {
                _VisibleRoles = value;
            }
        }

       
        
        private long _ClassID = 0L;

        public long ClassID
        {
            get { return _ClassID; }
            set { _ClassID = value; }
        }
        private short _ClassTypeID = 0;

        public short ClassTypeID
        {
            get { return _ClassTypeID; }
            set { _ClassTypeID = value; }
        }
        

        private ICmsClass _Class=new CmsClass();

        public ICmsClass Class
        {
            get { return _Class; }
            set { _Class = value; }
        }


        public string Data
        {
            get { return ExtPropertyList.ToXmlString(); }
            set { ExtPropertyList.FromXml(value); }
        }

        private byte[] _BinaryData;

        public byte[] BinaryData
        {
            get { return _BinaryData; }
            set { _BinaryData = value; }
        }

        private string[] _EditableRoles = new string[] { "SysAdmin" };
        public string[] EditableRoles
        {
            get
            {
                return _EditableRoles;
            }
            set
            {
                _EditableRoles = value;
            }
        }
    
        #endregion
 
        #region ICmsObject Members
        private IList<ICmsObject> _SubObjectList;
        public IList<ICmsObject> SubObjectList
        {
            get
            {
                return _SubObjectList;
            }
            set
            {
                _SubObjectList = value;
            }
        }


        public PropertyList ExtPropertyList
        {
            get { return Class.PropertyList; }
            set { Class.PropertyList = value; }

        }

        public IContentProperty GetExtProperty(string propertyName)
        {
            return ExtPropertyList.GetProperty(propertyName);
        }

        public object GetExtPropertyValue(string propertyName)
        {
            return ExtPropertyList.GetPropertyValue(propertyName);
        }
        public void SetExtPropertyValue(string propertyName, object value)
        {
            ExtPropertyList.SetPropertyValue(propertyName,value);
        }
        #endregion

        #region ICmsObject Members


        public bool FromCmsObject(ICmsObject obj)
        {
            try
            {
                this.ID = obj.ID;
                this.Name = obj.Name;
                this.Description = obj.Description;
                this.Data = obj.Data;
                this.ClassID = obj.ClassID;
                this.CreatedDate = obj.CreatedDate;
                this.BinaryData = obj.BinaryData;
                this.Class = obj.Class;
                this.Author = obj.Author;
                this.EditedBy = obj.EditedBy;
                this.EditedDate = obj.EditedDate;
                this.ExtPropertyList = obj.ExtPropertyList;
                this.FirstVersionID = obj.FirstVersionID;
                this.ParentID = obj.ParentID;
                this.Tags = obj.Tags;
                this.Version = obj.Version;
                this.EditableRoles = obj.EditableRoles;
                this.Status = obj.Status;

                this.Lang = obj.Lang;
                this.ExtPropertyList = obj.ExtPropertyList;
                //this.SubObjectList = obj.SubObjectList;
                return true;
            }
            catch
            {
                return false;
            }

        }

        #endregion

        #region IXml Members

        public bool FromXml(string xml)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public string ToXmlString()
        {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion

       
    }
}
